<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2011-12-20 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

require ROOT_PATH.'servlet/module/master.mod.php';

class moduleObj extends masterObj
{
	function __construct($request)
	{
		parent::__construct($request);
		
		require_once ROOT_PATH.'include/logic/image.logic.php';
		
		$this->excute();
	}
	
	function excute()
	{
		switch($this->act)
		{
			case 'category_list':
				$this->getCategoryList();
				break;
			case 'hot':
				$this->getHotPlayList();
				break;
			case 'expect':
				$this->getExpectedList();
				break;
			case 'list':
				$this->getMovieList();
				break;
			case 'desc';
				$this->getDesc();
				break;
			case 'refer':
				$this->getReferList();
				break;
			case 'titbit':
				$this->getTitbitList();
				break;
			case 'image_list':
				$this->getImageList();
				break;
			default:
				$this->message('004', STATUS_E);
		}
		
		$this->showResponse();
	}
	
	/**
	 * 
	 * Get movie category list
	 * 
	 */
	function getCategoryList()
	{
		$this->_checkUser();

		$results = get_movie_category_list();
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($results);
		$this->response['list'] = $results;
	}
	
	/**
	 * 
	 * Get movie list
	 * 
	 */
	function getHotPlayList()
	{		
		$request['from_id'] = $this->from_id;
		$request['to_id'] = $this->to_id;
		$request['page_limit'] = $this->page_limit;
		$request['page_num'] = $this->page_num;
		$request['is_hot'] = '1';
		
		//DBFunction::getInstance()->setDebug();
		
		$results = get_movie_list($request);
		
		$movie_list = array();
		
		if(check_array($results))
		{
			require ROOT_PATH.'servlet/include/output/movie.php';
			foreach($results as $item)
			{
				$item['actors'] = get_movie_actor_list($item['id']);
				$movie_list[] = new movie($item);
			}
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($movie_list);
		$this->response['list'] = $movie_list;
	}
	
	/**
	 * 
	 * Get expected movie list
	 */
	function getExpectedList()
	{		
		$request['from_id'] = $this->from_id;
		$request['to_id'] = $this->to_id;
		$request['page_limit'] = $this->page_limit;
		$request['page_num'] = $this->page_num;
		$request['is_expect'] = '1';
		
		$results = get_movie_list($request);
		
		$movie_list = array();
		
		if(check_array($results))
		{
			require ROOT_PATH.'servlet/include/output/movie.php';
			foreach($results as $item)
			{
				$item['actors'] = get_movie_actor_list($item['id']);
				$movie_list[] = new movie($item);
			}
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($movie_list);
		$this->response['list'] = $movie_list;
	}
	
	/**
	 * 
	 * Get movie list by category id
	 */
	function getMovieList()
	{		
		$category_list = get_movie_category_list();
		
		$categorys = array();
		foreach($category_list as $c)
		{
			$categorys[] = $c['id'];
		}
		
		if(!isset($this->request['cid']) || !in_array($this->request['cid'], $categorys))
		{
			$this->message('005', STATUS_E);
		}
		
		$request['from_id'] = $this->from_id;
		$request['to_id'] = $this->to_id;
		$request['page_limit'] = $this->page_limit;
		$request['page_num'] = $this->page_num;
		$request['category_id'] = (int)$this->request['cid'];
		
		$results = get_movie_list($request);
		
		$movie_list = array();
		
		if(check_array($results))
		{
			require ROOT_PATH.'servlet/include/output/movie.php';
			foreach($results as $item)
			{
				$item['actors'] = get_movie_actor_list($item['id']);
				$movie_list[] = new movie($item);
			}
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($movie_list);
		$this->response['list'] = $movie_list;
	}
	
	/**
	 * 
	 * Get movie info
	 */
	function getDesc()
	{		
		if(!isset($this->request['mid']) || !$this->request['mid'])
		{
			$this->message('005', STATUS_E);
		}
		
		$mid = (int)$this->request['mid'];
		$result = get_movie_desc($mid);
		
		if(!isset($result['movie_id']) || !$result['movie_id'])
		{
			$this->message('006', STATUS_F);
		}
		
		//$images = get_movie_images($result['movie_id'], BASE_URL, '1');
		
		$this->response['status'] = STATUS_S;
		$this->response['mid'] = $mid;
		$this->response['desc'] = $result['desc'];
		//$this->response['image_1'] = isset($images['image_1']) ? $images['image_1'] : '';
		//$this->response['image_2'] = isset($images['image_2']) ? $images['image_2'] : '';
		//$this->response['image_3'] = isset($images['image_3']) ? $images['image_3'] : '';
		//$this->response['image_o'] = isset($images['image_o']) ? $images['image_o'] : '';
	}
	
	/**
	 * 
	 * Get movie refer list
	 */
	function getReferList()
	{				
		if(!isset($this->request['mid']) || !$this->request['mid'])
		{
			$this->message('005', STATUS_E);
		}
		
		$request['from_id'] = $this->from_id;
		$request['to_id'] = $this->to_id;
		$request['page_limit'] = $this->page_limit;
		$request['page_num'] = $this->page_num;
		$request['movie_id'] = (int)$this->request['mid'];
		
		$results = get_movie_refer_list($request);
		
		$movie_refer_list = array();
		
		if(check_array($results))
		{
			foreach($results as $item)
			{
				$movie_refer_list[] = $item['refer'];
			}
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['mid'] = $request['movie_id'];
		$this->response['count'] = (string)count($movie_refer_list);
		$this->response['list'] = $movie_refer_list;
	}
	
	/**
	 * 
	 * Get movie titbit list
	 */
	function getTitbitList()
	{		
		if(!isset($this->request['mid']) || !$this->request['mid'])
		{
			$this->message('005', STATUS_E);
		}
		
		$request['from_id'] = $this->from_id;
		$request['to_id'] = $this->to_id;
		$request['page_limit'] = $this->page_limit;
		$request['page_num'] = $this->page_num;
		$request['movie_id'] = (int)$this->request['mid'];
		
		$results = get_movie_titbit_list($request);
		
		$movie_titbit_list = array();
		
		if(check_array($results))
		{
			foreach($results as $item)
			{
				$movie_titbit_list[] = $item['titbit_url'];
			}
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['mid'] = $request['movie_id'];
		$this->response['count'] = (string)count($movie_titbit_list);
		$this->response['list'] = $movie_titbit_list;
	}
	
	/**
	 * 
	 * Get movie image list
	 */
	function getImageList()
	{		
		if(!isset($this->request['mid']) || !$this->request['mid'])
		{
			$this->message('005', STATUS_E);
		}
		
		$mid = (int)$this->request['mid'];
		
		$image_list = get_movie_images($mid, BASE_URL);
		
		$this->response['status'] = STATUS_S;
		$this->response['mid'] = $mid;
		$this->response['count'] = (string)count($image_list);
		$this->response['list'] = $image_list;
	}
}